#define  _CRT_SECURE_NO_WARNINGS 1
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
#include<stdlib.h>
typedef struct ListNode SL;
struct ListNode* getIntersectionNode(struct ListNode* headA, struct ListNode* headB) {
    int n1 = 0;
    int n2 = 0;
    SL* pcur1 = headA;
    SL* pcur2 = headB;
    while (pcur1) {
        n1++;
        pcur1 = pcur1->next;
    }
    while (pcur2) {
        n2++;
        pcur2 = pcur2->next;
    }
    int cha = abs(n1 - n2);
    pcur1 = headA;
    pcur2 = headB;
    if (n1 > n2) {
        while (cha--) {
            pcur1 = pcur1->next;
        }
    }
    else {
        while (cha--) {
            pcur2 = pcur2->next;
        }
    }
    while (pcur1 && pcur2) {
        if (pcur1 == pcur2) {
            return pcur1;
        }
        pcur1 = pcur1->next;
        pcur2 = pcur2->next;
    }
    return NULL;
}